package edu.gatech.cs2340.mule.view;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;

import edu.gatech.cs2340.mule.presenter.MuleGamePresenter;

/**
 *
 */
public class MuleBuyingPanel extends JPanel {
	private static final int HGAP = 50;
	private static final int VGAP = 50;
	
	private JButton buyButton;
	private JButton cancelButton;
	private JComboBox muleTypeComboBox;
	private JLabel mulePriceLabel;
	
	public MuleBuyingPanel() {
		GridLayout layout = new GridLayout(3, 2);
		layout.setHgap(HGAP);
		layout.setVgap(VGAP);
		
		setLayout(layout);
		setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		
		muleTypeComboBox = new JComboBox(new DefaultComboBoxModel(new String[]{"Food M.U.L.E.","Energy M.U.L.E.","Smithore M.U.L.E."}));
		muleTypeComboBox.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		muleTypeComboBox.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		add(muleTypeComboBox);
		
		buyButton = new JButton();
		buyButton.setBackground(MuleGamePresenter.BACKGROUND_COLOR);
		buyButton.setBorder(new LineBorder(MuleGamePresenter.BACKGROUND_COLOR, 2));
		buyButton.setIcon(new ImageIcon("Images\\icon_buy.png"));
		add(buyButton);
		
		cancelButton = new JButton("Cancel");
		cancelButton.setBackground(MuleGamePresenter.FOREGROUND_COLOR);
		cancelButton.setForeground(MuleGamePresenter.BACKGROUND_COLOR);
		add(cancelButton);
		
		mulePriceLabel = new JLabel("<html><font size=+2>Price: ");
		mulePriceLabel.setForeground(MuleGamePresenter.FOREGROUND_COLOR);
		add(mulePriceLabel);
	}
	
	/**
	 * 
	 * @param a The action listener to add to the buy button
	 */
	public void addBuyListener(ActionListener a) {
		buyButton.addActionListener(a);
	}
	
	/**
	 * 
	 * @param a The action listener to add to the cancel button
	 */
	public void addCancelListener(ActionListener a) {
		cancelButton.addActionListener(a);
	}
	
	/**
	 * 
	 * @param i The item listener to add to the mule type combo box
	 */
	public void addComboListener(ItemListener i) {
		muleTypeComboBox.addItemListener(i);
	}
	
	/**
	 * 
	 * @return The type of mule the player selected to purchase
	 */
	public int getSelectedMuleType() {
		return muleTypeComboBox.getSelectedIndex();
	}
	
	/**
	 * Sets the price label's color to indicate the mule cannot be purchased
	 * 
	 */
	public void setPriceLabelColor() {
		mulePriceLabel.setForeground(new Color(154, 0, 0));
	}
	
	/**
	 * 
	 * @param price The price to display to the user
	 */
	public void updatelPriceLabel(int price) {
		mulePriceLabel.setText("<html><font size=+2>Price: " + price);
		mulePriceLabel.setForeground(new Color(0, 0, 0));
	}
}
